package software.literature.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import org.eclipse.swt.widgets.TreeItem;
/**
 * represent the data structure of tree in database.
 * @author Administrator
 *
 */
public class TreeTBItem {
private int id;
private String data;
private ArrayList<Integer> childrens_id;
private int parentId;
private TreeItem item;//refrence the item that belongs to this item
//this list is used only when this item is deleteed

public TreeTBItem(){
	setId(-1);
}
public String getChildrens_id_str() {
	int le=childrens_id.size();
	StringBuilder build=new StringBuilder();
	for(int i=0;i<le;i++){
		build.append(childrens_id);
		build.append(' ');
	}
	return build.toString();
}
public ArrayList<Integer> getChildrens_id() {
	return childrens_id;
}
public void setChildrens_id(String childrens_id) {
	if(childrens_id==null){
		return;
	}
	String[] s=childrens_id.split(" ");
	this.childrens_id=new ArrayList<Integer>();
	for(int i=0;i<s.length;i++){
		if(!s[i].equals("")){
			this.childrens_id.add(Integer.parseInt(s[i]));	
		}
	}
	Collections.sort(this.childrens_id);
}
public String getData() {
	return data;
}
public void setData(String data) {
	this.data = data;
}
/*public void insertSubItem(String itemId){
	childrens_id.add(itemId);
	Collections.sort(childrens_id);
}*/
/*@Override
public int compareTo(Object o) {
return this.id .compareTo(((TreeTBItem)o).id);
}*/
public int getId() {
	return id;
}
public void setId(int id) {
	this.id = id;
}
//@Override
//public int compareTo(Object arg0) {
//	// TODO Auto-generated method stub
//	return 0;
//}
public int getParentId() {
	return parentId;
}
public void setParentId(int parentId) {
	this.parentId = parentId;
}
public TreeItem getItem() {
	return item;
}
public void setItem(TreeItem item) {
	this.item = item;
}
}
